//
//  orderDetailViewController.m
//  ZPSALE
//
//  Created by tmosport on 14-5-28.
//  Copyright (c) 2014年 tmosport. All rights reserved.
//

#import "orderDetailViewController.h"
#import "showOrderViewController.h"
#import "alipayViewController.h"
#import "ZPBrandDetailVC.h"

@interface orderDetailViewController ()
{
    MBProgressHUD *hud;
}
@property (nonatomic,strong)NSString *productId;

@end

@implementation orderDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    _orderDetailWebView.delegate = self;
    [self setNavigationItem];
    // Do any additional setup after loading the view.
    self.title = @"订单详情";
    
   NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://m.zhenpin.com/index.php?c=APP_my&a=order&token=%@&orderid=%@&memberid=%@",_token,_orderId,_memberId]];
    //do:(@"%@",url);
    [_orderDetailWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
-(void)setNavigationItem {
    [self.navigationController.navigationBar setBackIndicatorImage:
     [UIImage imageNamed:@"return"]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:
     [UIImage imageNamed:@"return"]];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}

-(void)leftBarbuttonItemClicked:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
    
}

-(void)viewWillDisAppear:(BOOL)animated
{

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
    NSURL *url = [request URL];
    if ([[url scheme] isEqualToString:@"zpali"]) {
        [self alipay];
    }
    if ([[url scheme] isEqualToString:@"zpmallpid"]) {
        _productId = [NSString stringWithFormat:@"%@",[url query]];
        [self toBaseInfo];
    }
    return YES;
    
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"加载中...";
    hud.dimBackground = NO;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
//    hud.labelText = @"加载完成";
    [hud hide:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    hud.labelText = @"加载失败";
    [hud hide:YES afterDelay:1];
}
-(void)toBaseInfo{
    ZPBrandDetailVC *detailVC = (ZPBrandDetailVC *)[self.storyboard instantiateViewControllerWithIdentifier:@"ZPBrandDetailVC"];
    detailVC.productId = _productId;
    [self.navigationController pushViewController:detailVC animated:YES];
}

-(void)alipay{
    alipayViewController *destVC = [self.storyboard instantiateViewControllerWithIdentifier:@"alipayViewController"];
    destVC.memberId  = _memberId;
    destVC.token    = _token;
    destVC.orderId = _orderId;
    destVC.ordersn = _ordersn;
    destVC.needpay = _needpay;
    
    UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:destVC];
    navigationVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navigationVC.navigationBar.tintColor = [UIColor blackColor];
    // present
    [self presentViewController:navigationVC animated:YES completion:nil];
    
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    showOrderViewController *destVC = segue.destinationViewController;
    destVC.memberId  = _memberId;
    destVC.token    = _token;
}


@end
